package io.nads.config;

import io.nads.interceptor.AuthLoginInterceptor;
import io.nads.interceptor.GlobalInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@RequiredArgsConstructor
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    private final GlobalInterceptor globalInterceptor;
    private final AuthLoginInterceptor authLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(globalInterceptor)
                .addPathPatterns("/**")
                .order(0);
        
        // 启用登录认证拦截器，拦截需要用户认证的接口
        registry.addInterceptor(authLoginInterceptor)
                .addPathPatterns("/talk/**", "/users/**", "/session/**") // 需要认证的接口路径
                .excludePathPatterns("/talk/demo")
                .order(1);
    }
}
